package com.zxd.threads.thread_pool.callable_task;

import java.util.concurrent.*;

/**
 * ClassName:Test
 * Package:com.zxd.threads.thread_pool.callable_task
 *
 * @Date:2023/9/26 22:14
 * @Author:zxde
 */
public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPoolExecutor = new ThreadPoolExecutor(3, 5, 1,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(4), new ThreadPoolExecutor.AbortPolicy());

        //创建callable任务对象交给线程池执行，并且将结果封装为Future对象
        Future<String> result = threadPoolExecutor.submit(new MyCallable(9));
        Future<String> result1 = threadPoolExecutor.submit(new MyCallable(10));
        Future<String> result2 = threadPoolExecutor.submit(new MyCallable(22));
        Future<String> result3 = threadPoolExecutor.submit(new MyCallable(11));
        Future<String> result4 = threadPoolExecutor.submit(new MyCallable(4));
        //result.get()获得返回的结果
        System.out.println(result.get());
        System.out.println(result1.get());
        System.out.println(result2.get());
        System.out.println(result3.get());
        System.out.println(result4.get());
    }
}
